/**
 * @Author: hl
 * @Date: 2019/8/16
 * @Last Modified by: hl
 * @Last Modified time:
 */

import axios from '@/api/fetch';
// import * as types from './types';
import SERVER from '@/api/server';

// 单号查询 /stockmanage/partbuy/stockIn
export const stockIn = params => {
  return axios.get(`${SERVER.DMSCLOUD_PART}/stockmanage/partbuy/stockIn`, { params });
};

// 单号明细 /stockmanage/partbuy/stockInItem/{stockInNo}
export const partbuyStockInItem = ({ stockInNo }) => {
  return axios.get(`${SERVER.DMSCLOUD_PART}/stockmanage/partbuy/stockInItem/i=${stockInNo}`);
};
// 备件采购入库-查询符合条件的库存备件 /stockmanage/partbuy/findPartForAdd
// export const findPartForAdd = params => {
//   return axios.get(`${SERVER.DMSCLOUD_PART}/stockmanage/partbuy/findPartForAdd`, params);
// }

// 保存
export const partbuySave = params => {
  return axios.post(`${SERVER.DMSCLOUD_PART}/stockmanage/partbuy/save`, params);
};
// 删除整单数据
export const deleteWholeListClickMethod = params => {
  return axios.delete(`${SERVER.DMSCLOUD_PART}/stockmanage/partbuy/deleteWholeList/${params}`);
};
// 备件采购入库-入账 /stockmanage/partbuy/enterRecord
export const partbuyEnterRecord = params => {
  return axios.post(`${SERVER.DMSCLOUD_PART}/stockmanage/partbuy/enterRecord`, params);
};

// 退 查询已入库 /stockmanage/partbuy/queryForReturn
export const partbuyQueryForReturn = params => {
  return axios.get(`${SERVER.DMSCLOUD_PART}/stockmanage/partbuy/queryForReturn`, { params });
};
// 备件采购入库-查询退货备件最大可退货数量 /stockmanage/partbuy/canReturnNum/{OLD_STOCK_IN_NO}/{PART_NO}/{STORAGE_CODE}/{RETURN_ITME_ID}
export const partbuyQueryCanReturnNum = params => {
  return axios.get(`${SERVER.DMSCLOUD_PART}/stockmanage/partbuy/canReturnNum/${params.OLD_STOCK_IN_NO}/${params.PART_NO}/${params.STORAGE_CODE}/${params.RETURN_ITEM_ID}`);
};

// 发货单、采购订单、交易平台、文化公司 /stockmanage/partbuy/queryThreeTypeOrder
export const partgetfourData = params => {
  return axios.get(`${SERVER.DMSCLOUD_PART}/stockmanage/partbuy/queryThreeTypeOrder`, { params, timeout: 60000 });
};
// 发货单明细
export const partgetfourDataItems = params => {
  return axios.get(`${SERVER.DMSCLOUD_PART}/stockmanage/partbuy/queryTranslateItems`, { params, timeout: 60000 });
};
// 发货单、采购订单、交易平台、文化公司 明细 /stockmanage/partbuy/queryThreeTypeOrderDetail/{orderType}/{orderNo}
export const queryThreeTypeOrderDetail = params => {
  return axios.get(`${SERVER.DMSCLOUD_PART}/stockmanage/partbuy/queryThreeTypeOrderDetail/${params.orderType}/${params.orderNo}`);
};
// 查询所有员工 /sysManage/basedata/users/getUserListByRole
export const getDealerUser = params => axios.get(`${SERVER.DMSCLOUD_BASEDATA}/basedata/users/getDealerUser`);

// 根据备件代码和仓库代码查询可用库位
export const queryUsableLocations = params => axios.get(`${SERVER.DMSCLOUD_PART}/partMove/queryLocations`, { params });

//
export const queryPartInfo = async params => {
  const res = await axios.get(`${SERVER.DMSCLOUD_PART}/basedata/ttRepairOrder/queryPartInfo`, { params });
  if (res.data.rows.length === 0) {
    console.error('没有此备件，继续新增此备件吗');
  }
  return res;
};

// 采购入库打印接口
export const printData = (itemId, params) => {
  return axios.get(`${SERVER.DMSCLOUD_PART}/stockmanage/partbuy/queryPrintData/${itemId}/${params}`);
};

// 根据仓库备件代码查询备件是否存在
export const queryParyHasStorageById = params => axios.get(`${SERVER.DMSCLOUD_PART}/stockmanage/partbuy/getStorageByPartNo`, { params });

// 查询入库备件是否关联了欠料单
export const queryInventoryPartIsRelevanceInDebt = params => axios.get(`${SERVER.DMSCLOUD_PART}/stockmanage/partbuy/getShortPartNo`, { params });

// 欠料单备件点击完成
export const inDebtPartClickDone = params => axios.put(`${SERVER.DMSCLOUD_PART}/absentDetail/saveById`, params);

// 查询交易平台单号
export const queryPlatForm = params => axios.get(`${SERVER.DMSCLOUD_PART}/stockmanage/partbuy/platFormQuery`, { params });

// 根据仓库代码查询所有可用库位
export const queryUseablePositionListByStorage = params => axios.get(`${SERVER.DMSCLOUD_PART}/partMove/queryLocationsByStorage`, { params });
// 采购入库导出
export const exportData = params =>
  axios.get(`${SERVER.DMSCLOUD_PART}/stockmanage/partbuy/export`, {
    params,
    responseType: 'blob'
  });
export const partbuyStockInItemOEM = params => {
  return axios.get(`${SERVER.DMSCLOUD_PART}/stockmanage/partbuy/stockInItemOEM`, { params });
};
//审核
export const partbuyCheck = params => {
  return axios.post(`${SERVER.DMSCLOUD_PART}/stockmanage/partbuy/checkOrder`, params);
};
